/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package UML_ER.impl;

import UML_ER.BinaryRelationship;
import UML_ER.ReadingDirection;
import UML_ER.Role;
import UML_ER.UML_ERPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Binary Relationship</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link UML_ER.impl.BinaryRelationshipImpl#getSource <em>Source</em>}</li>
 *   <li>{@link UML_ER.impl.BinaryRelationshipImpl#getTarget <em>Target</em>}</li>
 *   <li>{@link UML_ER.impl.BinaryRelationshipImpl#getReadingDirection <em>Reading Direction</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BinaryRelationshipImpl extends RelationshipImpl implements BinaryRelationship {
	/**
	 * The cached value of the '{@link #getSource() <em>Source</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSource()
	 * @generated
	 * @ordered
	 */
	protected Role source;
	/**
	 * The cached value of the '{@link #getTarget() <em>Target</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTarget()
	 * @generated
	 * @ordered
	 */
	protected Role target;
	/**
	 * The default value of the '{@link #getReadingDirection() <em>Reading Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReadingDirection()
	 * @generated
	 * @ordered
	 */
	protected static final ReadingDirection READING_DIRECTION_EDEFAULT = ReadingDirection.S2T;
	/**
	 * The cached value of the '{@link #getReadingDirection() <em>Reading Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReadingDirection()
	 * @generated
	 * @ordered
	 */
	protected ReadingDirection readingDirection = READING_DIRECTION_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BinaryRelationshipImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return UML_ERPackage.Literals.BINARY_RELATIONSHIP;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Role getSource() {
		if (source != null && source.eIsProxy()) {
			InternalEObject oldSource = (InternalEObject)source;
			source = (Role)eResolveProxy(oldSource);
			if (source != oldSource) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, UML_ERPackage.BINARY_RELATIONSHIP__SOURCE, oldSource, source));
			}
		}
		return source;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Role basicGetSource() {
		return source;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSource(Role newSource) {
		Role oldSource = source;
		source = newSource;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UML_ERPackage.BINARY_RELATIONSHIP__SOURCE, oldSource, source));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Role getTarget() {
		if (target != null && target.eIsProxy()) {
			InternalEObject oldTarget = (InternalEObject)target;
			target = (Role)eResolveProxy(oldTarget);
			if (target != oldTarget) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, UML_ERPackage.BINARY_RELATIONSHIP__TARGET, oldTarget, target));
			}
		}
		return target;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Role basicGetTarget() {
		return target;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTarget(Role newTarget) {
		Role oldTarget = target;
		target = newTarget;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UML_ERPackage.BINARY_RELATIONSHIP__TARGET, oldTarget, target));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ReadingDirection getReadingDirection() {
		return readingDirection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setReadingDirection(ReadingDirection newReadingDirection) {
		ReadingDirection oldReadingDirection = readingDirection;
		readingDirection = newReadingDirection == null ? READING_DIRECTION_EDEFAULT : newReadingDirection;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UML_ERPackage.BINARY_RELATIONSHIP__READING_DIRECTION, oldReadingDirection, readingDirection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case UML_ERPackage.BINARY_RELATIONSHIP__SOURCE:
				if (resolve) return getSource();
				return basicGetSource();
			case UML_ERPackage.BINARY_RELATIONSHIP__TARGET:
				if (resolve) return getTarget();
				return basicGetTarget();
			case UML_ERPackage.BINARY_RELATIONSHIP__READING_DIRECTION:
				return getReadingDirection();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case UML_ERPackage.BINARY_RELATIONSHIP__SOURCE:
				setSource((Role)newValue);
				return;
			case UML_ERPackage.BINARY_RELATIONSHIP__TARGET:
				setTarget((Role)newValue);
				return;
			case UML_ERPackage.BINARY_RELATIONSHIP__READING_DIRECTION:
				setReadingDirection((ReadingDirection)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case UML_ERPackage.BINARY_RELATIONSHIP__SOURCE:
				setSource((Role)null);
				return;
			case UML_ERPackage.BINARY_RELATIONSHIP__TARGET:
				setTarget((Role)null);
				return;
			case UML_ERPackage.BINARY_RELATIONSHIP__READING_DIRECTION:
				setReadingDirection(READING_DIRECTION_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case UML_ERPackage.BINARY_RELATIONSHIP__SOURCE:
				return source != null;
			case UML_ERPackage.BINARY_RELATIONSHIP__TARGET:
				return target != null;
			case UML_ERPackage.BINARY_RELATIONSHIP__READING_DIRECTION:
				return readingDirection != READING_DIRECTION_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (readingDirection: ");
		result.append(readingDirection);
		result.append(')');
		return result.toString();
	}

} //BinaryRelationshipImpl
